package com.cat.dynamicPlanning;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/palindromic-substrings/
 * @create 2025/9/6 18:39
 * @since JDK17
 */

public class Solution89 {
    public int countSubstrings(String s) {
        int n = s.length(), ans = 0;
        boolean[][] dp = new boolean[n][n];
        for (int l = n - 1; l >= 0; l--) {
            for (int r = l; r < n; r++) {
                if (s.charAt(l) == s.charAt(r) && (r - l <= 1 || dp[l + 1][r - 1])) {
                    dp[l][r] = true;
                    ans++;
                }
            }
        }
        return ans;
    }
}
